﻿using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace AudioBooks.Common
{
    public class HtmlExtention
    {
        public static string GetHTML(DependencyObject obj)
        {
            return (string)obj.GetValue(HTMLProperty);
        }

        public static void SetHTML(DependencyObject obj, string value)
        {
            obj.SetValue(HTMLProperty, value);
        }

        // Using a DependencyProperty as the backing store for HTML.  This enables animation, styling, binding, etc...  
        public static readonly DependencyProperty HTMLProperty =
            DependencyProperty.RegisterAttached("HTML", typeof(string), typeof(HtmlExtention), new PropertyMetadata(0, new PropertyChangedCallback(OnHTMLChanged)));

        
        private static void OnHTMLChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

            WebView wv = d as WebView;
            if (wv != null)
            {
                string content  = e.NewValue.ToString();
                string regex = @"(color:.+?;)";

                content = System.Text.RegularExpressions.Regex.Replace(content,regex,"color:" +"White"+ ";");

                wv.NavigateToString(content);
            }
        }

    }
}
